package pubsub

import (
	"context"
	"time"
)

// Identifier for a particular message
type MessageID interface {
	// Serialize the message id into a sequence of bytes that can be stored somewhere else
	Serialize() []byte
}

type Message interface {
	//Topic Get the topic from which this message originated from
	Topic() string
	// Return the properties attached to the message.
	// Properties are application defined key/value pairs that will be attached to the message
	Properties() map[string]string
	//Payload Get the payload of the message
	Payload() []byte
	//ID Get the unique message ID associated with this message.
	// The message id can be used to univocally refer to a message without having the keep the entire payload in memory.
	ID() MessageID
	//PublishTime Get the publish time of this message. The publish time is the timestamp that a client publish the message.
	PublishTime() time.Time
	//EventTime Get the event time associated with this message. It is typically set by the applications via
	// `ProducerMessage.EventTime`.
	// If there isn't any event time associated with this event, it will be nil.
	EventTime() *time.Time
	//Key Get the key of the message, if any
	Key() string
	//Value Get the de-serialized value of the message, according the configured
	Value(v interface{}) error
	//Context Get the context which contain trace and metadata
	Context() context.Context
	//Ack the consumption of a single message
	Ack() error
}

// ctx is equal to message.Context()
type MessageHandler func(ctx context.Context, message Message) error

type Subscriber interface {
	// DEPRECATED: USE START INSTEAD.
	Receive(ctx context.Context) (Message, error)
	//Close stop receive message, and close any connection to the broker
	Close() error
	//Start start a loop to receive message from broker, and dispath to handler
	Start(ctx context.Context, handler MessageHandler) error
}
